package shiyan2;

public class AnimalTest {
    public static void main(String[] args) {
        Animal[] animals = new Animal[2];
        animals[0] = new Dog("Wangwang", 2, "Black Retriever");
        animals[1] = new Cat("Mimi", 1, "Brown");

        for (Animal animal : animals) {
            System.out.println("Name: " + animal.getName() + ", Age: " + animal.getAge());

            if (animal instanceof Dog) {
                Dog dog = (Dog) animal;
                System.out.println("Breed: " + dog.getBreed());
            } else if (animal instanceof Cat) {
                Cat cat = (Cat) animal;
                System.out.println("Fur Color: " + cat.getFurColor());
            }

            animal.makeSound();

            if (animal instanceof Swimmable) {
                ((Swimmable) animal).swim();
            }

            if (animal instanceof Trainable) {
                ((Trainable) animal).train();
            }
        }
    }
}